<?php session_start();
validaAcesso();

echo "<h2>".$_SESSION["menu"]["rel"][14]." ".$_SESSION["NOME_HOSTEL_"]."</h2>";

?>
 <script type="text/javascript" src="css2/calendar/dhtmlgoodies_calendar.js"></script>
            <br><form method='POST' action='index.jsp?rel=14&cont=1' autocomplete='off'>
            
              <b>Data Inicial:</b>
              <input type="text" value="<?php echo date("d/m/Y"); ?>" readonly name="pdatai"  id="pdatai" id="pdatai">
              <img src="images/data.gif" border="0" style="cursor:hand;" onclick="displayCalendar(document.getElementById('pdatai'),'dd/mm/yyyy',this);">

              &nbsp;<b>Data Final:</b>
              <input type="text" value="<?php echo date("d/m/Y"); ?>" readonly name="pdataf"  id="pdataf" id="pdataf">
              <img src="images/data.gif" border="0" style="cursor:hand;" onclick="displayCalendar(document.getElementById('pdataf'),'dd/mm/yyyy',this);"><br><br>


          <input type='submit' value='Gerar Estat&iacute;stica'>
			<div align='right'><a href="javascript:void(0);" onclick="getLink('rel',7,false);"><img src='images/seta_voltar.gif' border='0'> voltar para Listagem de Relat&oacute;rios</a></div>
        </form>               

<?php
if($_GET["cont"]==1){


	$novo_datai=formataData($_POST["pdatai"], true);
	$novo_dataf=formataData($_POST["pdataf"], true);



	$sql="
			SELECT 
				res.id_reserva, 
				res.nome, 
				lan.num_comanda, 
				lan.data_Cadastro, 
				sum( lan.valor ),
				lan.valor
			FROM 
				(hostel_reservas res, 
				hostel_lancamentos lan)
			WHERE 				
				(res.id_hostel = {$_SESSION["ID_HOSTEL_"]}) AND
				(res.id_reserva = lan.id_reserva) AND
				(lan.data_Cadastro between   '$novo_datai' and '$novo_dataf') 
			GROUP BY 
			(res.id_reserva)
";


	$linha=$_SESSION['ADOCnn']->Execute("$sql");

	$n=0;
	$valor_total=0;
	$valor=0;

	if($linha->RecordCount() != 0 ){
		
################# estrutura da tabela ###################
		$periodo = "Per&iacute;odo: ".formataData($novo_datai)." At&eacute; ".formataData($novo_dataf);
		echo "<h2>$periodo</h2>";

		echo "<table class='perfil $class'>

	<table class='perfil'>
	<tr class='titulo'>
	<td width=110 align='center'>ID_reserva</td>
	<td width=100>Nome</td>
	<td width=100 align='center'>N. Comanda</td>
	<td width=100 align='center'>Data da Compra</td>
	<td width=110 align='center'>Valor da Despesa</td>
	</tr>
	";   
		$class="odd";
################# fim estrutura ##############

		while(!$linha->EOF){

			// cores das linhas da tabela
			if($class == "odd"){$class="even";}else{$class="odd";}

			$data=formatadata($linha->fields['data_Cadastro']);

			$valor = $linha->fields[4];

			$valor_total = $valor_total + $valor;

			echo"
	<tr class='$class'>	
	<td align='center'>{$linha->fields['id_reserva']}</td>
	<td>{$linha->fields['nome']}</td>
	<td align='center'>{$linha->fields['num_comanda']}</td>
	<td align='center'>$data</td>
	<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".formataValor($linha->fields[4],true,false)."</td>

	</tr>

	";
			$n++;
			$linha->MoveNext();

		}

		//			$res_valor = number_format($valor_total,'2',',','.');   tambem da certo

		echo "</table><br><b>Resultados:</b> <u>$n</u><br>";
		echo "<b>Valor Total Geral:</b> <u>".formataValor($valor_total,true,false)."</u>";
	}
}


?>

